package com.zmx.mq.task.messaging.queue;

import com.zmx.common.common.contents.MqQueueContents;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 服务请求日志队列
 * @ClassName: RequestLogQueue
 * @Author zhaomx
 * @Version 1.0
 * @Date 2021-11-13 19:30
 */
@Configuration
public class RequestLogQueue {

    @Bean("saverRequestLogQueue")
    public Queue saverRequestLogQueue() {
        return new Queue(MqQueueContents.SAVE_REQUEST_LOG_QUEUE);
    }

    @Bean("saverRequestLogExchange")
    public FanoutExchange saverRequestLogExchange() {
        return new FanoutExchange(MqQueueContents.SAVE_REQUEST_LOG_EXCHANGE, true, false, null);
    }

    @Bean
    public Binding saverRequestLogBinding(@Qualifier("saverRequestLogQueue") Queue queue, @Qualifier("saverRequestLogExchange") FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
}
